package com.dameng.jianyouquan.mvp.model;

import android.content.Context;

import com.dameng.jianyouquan.api.Constant;
import com.dameng.jianyouquan.bean.SwichRoleBean;
import com.dameng.jianyouquan.api.NetWorkManager;
import com.dameng.jianyouquan.utils.SpUtils;

import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class ChooseIdentityModel {


    public void ChooseIdentity_Model(Context context, String type,OnChooseListener listener) {

//        listener.ChooseSuccess(type);

        String userId = SpUtils.getValue(context, Constant.SP_UID);
        NetWorkManager.getService()
                .getSaveUserRole(userId, type)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<SwichRoleBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.ChooseFail(e.getMessage()+"");
                    }

                    @Override
                    public void onNext(SwichRoleBean swichRoleBean) {
                        int code = swichRoleBean.getCode();
                        if (code==200){
                            listener.ChooseSuccess(type);
                        }else {
                            listener.ChooseFail(swichRoleBean.getMsg());
                        }
                    }
                });


    }


    public interface OnChooseListener {

        void ChooseSuccess(String type);

        void ChooseFail(String msg);
    }
}
